<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" xmlns:shiro="http://www.pollix.at/thymeleaf/shiro">
<head>
    <th:block th:include="include :: header('住宿生信息列表')" />
</head>
<body class="gray-bg">
     <div class="container-div">
        <div class="row">
            <div class="col-sm-12 search-collapse">
                <form id="formId">
                    <div class="select-list">
                        <ul>
                            <li>
                                <label> 学生宿舍：</label>
                                <div class="col-sm-4">
                                    <select id="dormitoryNum" name="dormitoryNum" class="form-control">
                                    <option th:each="dormitory : ${dormitorylist}" th:text="${dormitory['dormitoryNum']}" th:value="${dormitory['dormitoryNum']}" th:field="*{dormitory.dormitoryNum}"></option>
                                    </select>
                                </div>
                            </li>
                            <li>
                                <label>学生姓名：</label>
                                <input type="text" name="stuName"/>
                            </li>
                            <li>
                                <label>年级：</label>
                                <div class="col-sm-4">
                                    <select name="stuGrade" th:with="type=${@dict.getType('sys_grade_num')}">
                                        <option value="">所有</option>
                                        <option th:each="dict : ${type}" th:text="${dict.dictLabel}" th:value="${dict.dictValue}"></option>
                                    </select>
                                </div>
                            </li>
                            <li>
                                <label>班级：</label>
                                <div class="col-sm-4">
                                    <input type="text" name="stuClass" placeholder="请输入班级号"/>
                                </div>
                            </li>
                            <li>
                                <label>状态：</label>
                                <select name="status" th:with="type=${@dict.getType('sys_dormitory_status')}">
                                    <option value="">所有</option>
                                    <option th:each="dict : ${type}" th:text="${dict.dictLabel}" th:value="${dict.dictValue}"></option>
                                </select>
                            </li>
                            <li>
                                <a class="btn btn-primary btn-rounded btn-sm" onclick="$.table.search()"><i class="fa fa-search"></i>&nbsp;搜索</a>
                                <a class="btn btn-warning btn-rounded btn-sm" onclick="resetPre()"><i class="fa fa-refresh"></i>&nbsp;重置</a>
                            </li>
                        </ul>
                    </div>
                </form>
            </div>

            <div class="btn-group-sm" id="toolbar" role="group">
                <a class="btn btn-success" onclick="add()" shiro:hasPermission="nczxsushe:stumanage:add">
                    <i class="fa fa-plus"></i> 添加
                </a>
                <a class="btn btn-primary single disabled" onclick="$.operate.edit()" shiro:hasPermission="nczxsushe:stumanage:edit">
                    <i class="fa fa-edit"></i> 修改
                </a>
                <a class="btn btn-danger multiple disabled" onclick="$.operate.removeAll()" shiro:hasPermission="nczxsushe:stumanage:remove">
                    <i class="fa fa-remove"></i> 删除
                </a>
                <a class="btn btn-warning" onclick="$.table.exportExcel()" shiro:hasPermission="nczxsushe:stumanage:export">
                    <i class="fa fa-download"></i> 导出
                </a>
            </div>
            <div class="col-sm-12 select-table table-striped">
                <table id="bootstrap-table"></table>
            </div>
        </div>
    </div>
    <th:block th:include="include :: footer" />
    <script th:inline="javascript">
        var editFlag = [[${@permission.hasPermi('nczxsushe:dormitory:edit')}]];
        var removeFlag = [[${@permission.hasPermi('nczxsushe:dormitory:remove')}]];
        var detailFlag = [[${@permission.hasPermi('nczxsushe:dormitory:detail')}]];
        var stuGradeDatas = [[${@dict.getType('sys_grade_num')}]];
        var statusDatas = [[${@dict.getType('sys_dormitory_status')}]];
        var prefix = ctx + "nczxsushe/dormitory/student";

        $(function() {
            var options = {
                url: prefix + "/list",
                createUrl: prefix + "/add",
                updateUrl: prefix + "/edit/{id}",
                removeUrl: prefix + "/remove",
                exportUrl: prefix + "/export",
                queryParams: queryParams,
                sortName: "stuBedno",
                sortOrder: "asc",
                modalName: "住宿生信息",
                columns: [{
                    checkbox: true
                },
                {
                    field: 'sid',
                    title: '主键',
                    visible: false
                },
                {
                    title: "序号",
                    formatter: function (value, row, index) {
                        return $.table.serialNumber(index);
                    }
                },
                {
                    field: 'stuName',
                    title: '学生姓名'
                },
                {
                    field: 'stuGrade',
                    title: '年级',
                    formatter: function(value, row, index) {
                       return $.table.selectDictLabel(stuGradeDatas, value);
                    }
                },
                {
                    field: 'stuClass',
                    title: '班级'
                },
                {
                    field: 'stuBedno',
                    title: '床号'
                },
                {
                    field: 'stuTell',
                    title: '联系电话'
                },
                {
                    field: 'stuAddress',
                    title: '家庭住址'
                },
                {
                    field: 'stuAvatar',
                    title: '照片',
                    formatter: function(value, row, index) {
                        return $.table.imageView(value);
                    }
                },
                {
                    field: 'stustatus',
                    title: '状态',
                    formatter: function(value, row, index) {
                       return $.table.selectDictLabel(statusDatas, value);
                    }
                },
                {
                    field: 'inDate',
                    title: '入住时间',
                    //获取日期列的值进行转换
                    formatter: function (value, row, index) {
                        if (value===null)
                        {
                            return "未填写";
                        }
                        else
                        {
                            return $.common.dateFormat(value,'yyyy-MM-dd');
                        }
                    }
                },
                {
                    field: 'outDate',
                    title: '退宿时间',
                    //获取日期列的值进行转换
                    formatter: function (value, row, index) {
                        if (value===null)
                        {
                            return "在住";
                        }
                        else
                        {
                            return $.common.dateFormat(value,'yyyy-MM-dd');
                        }
                    }
                },
                {
                    field: 'remark',
                    title: '备注'
                },
                {
                    title: '操作',
                    align: 'center',
                    formatter: function(value, row, index) {
                        var actions = [];
                        actions.push('<a class="btn btn-success btn-xs ' + editFlag + '" href="javascript:void(0)" onclick="$.operate.edit(\'' + row.sid + '\')"><i class="fa fa-edit"></i>编辑</a> ');
                        actions.push('<a class="btn btn-info btn-xs ' + detailFlag + '" href="javascript:void(0)" onclick="detail(\'' + row.sid + '\')"><i class="fa fa-search"></i>详情</a> ');
                        actions.push('<a class="btn btn-danger btn-xs ' + removeFlag + '" href="javascript:void(0)" onclick="$.operate.remove(\'' + row.sid + '\')"><i class="fa fa-remove"></i>删除</a>');
                        return actions.join('');
                    }
                }]
            };
            $.table.init(options);
        });
        /**查询宿舍号过滤*/
        function queryParams(params) {
            var search = $.table.queryParams(params);
            search.dormitoryNum = $("#dormitoryNum").val();
            console.log(search)
            return search;
        }

        /**新增住校生信息-带着宿舍号*/
        function add() {
            var dormitoryNum = $("#dormitoryNum option:selected").val();
            $.modal.open("新增住校生信息",prefix+"/add/"+dormitoryNum);
        }

        /**点击重置时初始化宿舍号*/
        function resetPre() {
            $.form.reset();
            $("#dormitoryNum").val($("#dormitoryNum").val()).trigger("change");
        }

        /**点击查看详情*/
        function detail(id) {
            $.modal.open("住宿生详情信息",prefix+"/detail/"+id,"600","600")
        }
    </script>
</body>
</html>